package shop;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import shop.*;
import admin.*;

import com.opensymphony.xwork2.ActionSupport;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import java.util.*;
import java.io.Reader;
import java.io.IOException;

import member.Memberbean;

import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionContext;
import java.util.Map;

public class OrderAddAction extends ActionSupport implements SessionAware{

	public static Reader reader;
	public static SqlMapClient sqlMapper;
	Map session;

	private OrderBean result;
	
	private String ORDER_TRADE_NUM;
	private String ORDER_TRANS_NUM;
	private int ORDER_GOODS_NUM;
	private String ORDER_GOODS_NAME;
	private int ORDER_GOODS_AMOUNT; 
	private String ORDER_GOODS_SIZE;
	private String ORDER_M_ID;
	private String ORDER_RECEIVE_NAME;
	private String ORDER_RECEIVE_ADDR1;
	private String ORDER_RECEIVE_ADDR2;
	private String ORDER_RECEIVE_HP;
	private String ORDER_MEMO;
	private int ORDER_SUM_MONEY;
	private String ORDER_TRADE_TYPE;
	private String ORDER_TRADE_PAYER;

	public OrderAddAction() throws IOException {
		reader = Resources.getResourceAsReader("sqlMapConfig.xml");
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
		reader.close();

	}
	
	public String execute() throws Exception {

		result = new OrderBean();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		
		ActionContext context=ActionContext.getContext();
		Map<String,Object> session = context.getSession();		
		String id=(String)session.get("session_m_id");
		
		result.setORDER_TRADE_NUM(sdf.format(Calendar.getInstance().getTime()).toString()+"-"+ORDER_GOODS_NUM);
		result.setORDER_TRANS_NUM("");
		result.setORDER_GOODS_NUM(getORDER_GOODS_NUM());
		result.setORDER_GOODS_NAME(getORDER_GOODS_NAME());
		result.setORDER_GOODS_AMOUNT(getORDER_GOODS_AMOUNT());
		result.setORDER_GOODS_SIZE(getORDER_GOODS_SIZE());
		result.setORDER_M_ID(id);
		result.setORDER_RECEIVE_NAME(getORDER_RECEIVE_NAME());
		result.setORDER_RECEIVE_ADDR1(getORDER_RECEIVE_ADDR1());
		result.setORDER_RECEIVE_ADDR2(getORDER_RECEIVE_ADDR2());
		result.setORDER_RECEIVE_HP(getORDER_RECEIVE_HP());
		result.setORDER_MEMO(getORDER_MEMO());
		result.setORDER_SUM_MONEY(getORDER_SUM_MONEY());
		result.setORDER_TRADE_TYPE(getORDER_TRADE_TYPE());
		result.setORDER_TRADE_PAYER(getORDER_TRADE_PAYER());
		
		sqlMapper.insert("insertGoodsOrder",result);
		
		return SUCCESS;
	}
	public OrderBean getResult() {
		return result;
	}
	public void setResult(OrderBean result) {
		this.result = result;
	}
	public Map getSession() {
		return session;
	}
	public void setSession(Map session) {
		this.session = session;
	}
	public String getORDER_TRADE_NUM() {
		return ORDER_TRADE_NUM;
	}
	public void setORDER_TRADE_NUM(String order_trade_num) {
		ORDER_TRADE_NUM = order_trade_num;
	}
	public String getORDER_TRANS_NUM() {
		return ORDER_TRANS_NUM;
	}
	public void setORDER_TRANS_NUM(String order_trans_num) {
		ORDER_TRANS_NUM = order_trans_num;
	}
	public int getORDER_GOODS_NUM() {
		return ORDER_GOODS_NUM;
	}
	public void setORDER_GOODS_NUM(int order_goods_num) {
		ORDER_GOODS_NUM = order_goods_num;
	}
	public String getORDER_GOODS_NAME() {
		return ORDER_GOODS_NAME;
	}
	public void setORDER_GOODS_NAME(String order_goods_name) {
		ORDER_GOODS_NAME = order_goods_name;
	}
	public int getORDER_GOODS_AMOUNT() {
		return ORDER_GOODS_AMOUNT;
	}
	public void setORDER_GOODS_AMOUNT(int order_goods_amount) {
		ORDER_GOODS_AMOUNT = order_goods_amount;
	}
	public String getORDER_GOODS_SIZE() {
		return ORDER_GOODS_SIZE;
	}
	public void setORDER_GOODS_SIZE(String order_goods_size) {
		ORDER_GOODS_SIZE = order_goods_size;
	}
	public String getORDER_M_ID() {
		return ORDER_M_ID;
	}
	public void setORDER_M_ID(String order_m_id) {
		ORDER_M_ID = order_m_id;
	}
	public String getORDER_RECEIVE_NAME() {
		return ORDER_RECEIVE_NAME;
	}
	public void setORDER_RECEIVE_NAME(String order_receive_name) {
		ORDER_RECEIVE_NAME = order_receive_name;
	}
	public String getORDER_RECEIVE_ADDR1() {
		return ORDER_RECEIVE_ADDR1;
	}
	public void setORDER_RECEIVE_ADDR1(String order_receive_addr1) {
		ORDER_RECEIVE_ADDR1 = order_receive_addr1;
	}
	public String getORDER_RECEIVE_ADDR2() {
		return ORDER_RECEIVE_ADDR2;
	}
	public void setORDER_RECEIVE_ADDR2(String order_receive_addr2) {
		ORDER_RECEIVE_ADDR2 = order_receive_addr2;
	}
	public String getORDER_RECEIVE_HP() {
		return ORDER_RECEIVE_HP;
	}
	public void setORDER_RECEIVE_HP(String order_receive_hp) {
		ORDER_RECEIVE_HP = order_receive_hp;
	}
	public String getORDER_MEMO() {
		return ORDER_MEMO;
	}
	public void setORDER_MEMO(String order_memo) {
		ORDER_MEMO = order_memo;
	}
	public int getORDER_SUM_MONEY() {
		return ORDER_SUM_MONEY;
	}
	public void setORDER_SUM_MONEY(int order_sum_money) {
		ORDER_SUM_MONEY = order_sum_money;
	}
	public String getORDER_TRADE_TYPE() {
		return ORDER_TRADE_TYPE;
	}
	public void setORDER_TRADE_TYPE(String order_trade_type) {
		ORDER_TRADE_TYPE = order_trade_type;
	}
	public String getORDER_TRADE_PAYER() {
		return ORDER_TRADE_PAYER;
	}
	public void setORDER_TRADE_PAYER(String order_trade_payer) {
		ORDER_TRADE_PAYER = order_trade_payer;
	}
}
